package com.salts.controller;

import com.salts.domain.po.ClothCategory;
import com.salts.domain.vo.DisplayClothVo;
import com.salts.service.SortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sort")
public class SortServiceController {
    @Autowired
    SortService sortService;

    /**
     * 查询一级分类接口 /categoryOne -Get
     */
    @RequestMapping("/categoryOne")
    public List<String> getCategoryOneBySex(String sex){
        List<String> categoryOneBySex = sortService.getCategoryOneBySex(sex);
        return categoryOneBySex;
    }

    /**
     * 获取二级分类接口 -Get
     */
    @RequestMapping("/categoryTwo")
    public List<String> getCategoryTwo(String categoryTre,String categoryOne){
        return sortService.getCategoryTwo(categoryTre,categoryOne);
    }

    /**
     *  获取分类下商品的接口 /productDetails -Get
     * @param category
     * @return
     */
    @RequestMapping("/productDetails")
    public List<DisplayClothVo> getCategoryProduct(ClothCategory category,String clothName){
        if (StringUtils.isEmpty(clothName)){
            return  sortService.getCategoryProduct(category);//category.getCategoryOne(),category.getCategoryTwo(),category.getCategoryTre()
        }
        return  sortService.getProduct(clothName);
    }

    /**
     * 服装名称查询
     * @param clothName
     * @return
     */
    @RequestMapping("/getClothByName")
    public List<DisplayClothVo> getProduct(String clothName){
        return  sortService.getProduct(clothName);//category.getCategoryOne(),category.getCategoryTwo(),category.getCategoryTre()
    }
}
